package com.ny.service.impl;

import com.ny.entity.Devices;
import com.ny.mapper.DevicesMapper;
import com.ny.service.DevicesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DevicesServiceImpl implements DevicesService {

    @Autowired
    private DevicesMapper devicesMapper;


    @Override
    public List<Devices> findAll() {
        return devicesMapper.findAll();
    }
    
    @Override
    public List<Devices> findByName(String name) {
        return devicesMapper.findByName(name);
    }
    
    @Override
    public List<Devices> findByNameContaining(String name) {
        return devicesMapper.findByNameContaining(name);
    }
    
    @Override
    public Devices save(Devices devices) {
        return devicesMapper.save(devices);
    }
    
    @Override
    public Devices update(Devices devices) {
        // MongoRepository的save方法既可以创建也可以更新
        // 如果传入的对象有ID且存在，则更新；否则创建新记录
        return devicesMapper.save(devices);
    }
    
    @Override
    public void deleteById(String id) {
        devicesMapper.deleteById(id);
    }
}